'''
Function:
    定义一些精灵类
author:
    walker
time:
    2020/5/10
'''
from config import *

'''墙类'''
class Wall(pygame.sprite.Sprite):
    def __init__(self,x,y,**kwargs):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface([20,6])
        self.image.fill(SKYBLUE)
        self.rect = self.image.get_rect()
        self.rect.left = y*30
        self.rect.top = x*60

'''玩家信息'''
class Player(pygame.sprite.Sprite):
    def __init__(self,x,y,image_path,**kwargs):
        pygame.sprite.Sprite.__init__(self)
        self.base_image = pygame.image.load(image_path).convert()
        self.image = self.base_image.copy()
        self.rect = self.image.get_rect()
        self.rect.left = y*30
        self.rect.top = x*60
        self.speed = [0,0]
        self.base_speed = [30, 60]
        self.water_num = 0
        self.fire_num = 0
        self.is_move = False
        self.orient_list = []

    '''时空扭曲'''
    def trans(self,pos,trans_list):
        self.rect.left = trans_list[pos].left
        self.rect.top = trans_list[pos].top
        x_prev = self.rect.left
        y_prev = self.rect.top

    '''移动'''
    def move(self,direction):
        self.speed = [direction[0] * self.base_speed[0], direction[1] * self.base_speed[1]]
        return self.speed

    '''更新角色位置'''
    def update(self, wall_sprites,start,orient):
        if not self.is_move:
            return False
        x_prev = self.rect.left
        y_prev = self.rect.top

        self.rect.left += self.speed[0]
        self.rect.top += self.speed[1]

        is_collide = pygame.sprite.spritecollide(self, wall_sprites, False)
        if not is_collide:
            #将运动路径加入进去
            if orient and self.rect.left >= 0 and self.rect.top >= 0:
                self.orient_list.append(orient)
            if self.rect.left < 0 or self.rect.top < 0:
                self.rect.left = start[1] * 30
                self.rect.top = start[0] * 60
            return True
        else:
            self.rect.left = x_prev
            self.rect.top = y_prev
            return False

'''水、火、终点、传送点角色'''
class charactor(pygame.sprite.Sprite):
    def __init__(self,x,y,image_path,**kwargs):
        pygame.sprite.Sprite.__init__(self)
        self.base_image = pygame.image.load(image_path).convert()
        self.image = self.base_image.copy()
        self.rect = self.image.get_rect()
        self.rect.left = y*30
        self.rect.top = x*60
